package cn.tedu.egarticle.base.interceptor;

import cn.tedu.egarticle.pojo.vo.UserVo;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.springframework.web.servlet.HandlerInterceptor;

public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        UserVo user = (UserVo) session.getAttribute("user");
        if (user == null) {
            throw new RuntimeException("用户未登录");
        }
        return true;
    }
}
